package com.eujian.nacosconfig.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;
import org.springframework.core.env.Environment;

import java.util.Set;
@Slf4j
@Configuration
public class ConfigChangeLister {
    @Autowired
    private Environment environment;

    @EventListener
    public void getUserEvent(EnvironmentChangeEvent event) {
        Set<String> keys = event.getKeys();
        keys.forEach(k->{
            String v = environment.getProperty(k);
            log.info("配置变更，key={},value={}",k,v);
        });
    }
}
